#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 35;
const int MOD = 2017;
int n, m, t;
int a[N][N];
void matmul(int a[N][N], int b[N][N], int c[N][N]) {
  int res[N][N] = {0};
  rep(i, 0, n) rep(j, 0, n) rep(k, 0, n) {
    res[i][j] = (res[i][j] + a[i][k] * b[k][j]) % MOD;
  }
  rep(i, 0, n) rep(j, 0, n) c[i][j] = res[i][j];
}
void matpow(int b[N][N], int p, int c[N][N]) {
  int res[N][N] = {0};
  rep(i, 0, n) res[i][i] = 1;
  while (p) {
    if (p & 1) matmul(res, b, res);
    matmul(b, b, b);
    p >>= 1;
  }
  rep(i, 0, n) rep(j, 0, n) c[i][j] = res[i][j];
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  while (m--) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    a[u][v] = a[v][u] = 1;
  }
  rep(i, 0, n) a[i][i] = 1, a[i][n] = 1;
  cin >> t;
  matpow(a, t, a);
  int ans = 0;
  rep(i, 0, n) ans = (ans + a[0][i]) % MOD;
  cout << ans;
  return 0;
}